/*
 * 卧虎藏龙
 */
var mobid;
var setupTask;
var mob;
var modified;
var MapList = Array(
		253000100, //BOSS地图1
		253000200, //BOSS地图2
		253000300 //BOSS地图2
	);

function init() {
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
}

function setup(level, leaderid) {
	em.setProperty("state", "1");
	em.setProperty("leader", "true");
	var eim = em.newInstance("ZChaosPQ11");
	for (var i = 0; i < MapList.length; i++) {
		var map = eim.setInstanceMap(MapList[i]);
		map.resetPQ(level);
		map.resetFully();
		map.killAllMonsters(true);
	}

	var map = eim.setInstanceMap(253000100);
	mobid = 9601013;
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(80000000);
	modified.setOMp(1000000000);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob8 = eim.getMapInstance(253000100);
	mapForMob8.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-1, 128));

	mobid = 9601015;
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(160000000);
	modified.setOMp(1000000000);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob8 = eim.getMapInstance(253000300);
	mapForMob8.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-13, 95));

	mobid = 9601018;
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(320000000);
	modified.setOMp(1000000000);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob8 = eim.getMapInstance(253000200);
	mapForMob8.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-13, 95));

	return eim;
}

function playerEntry(eim, player) {
	var map = eim.getMapInstance(0);
	player.dropMessage(6, "开始挑战，限时60分钟。");
	player.changeMap(map, map.getPortal(0));
}

function playerRevive(eim, player) {
	return true;
}

function changedMap(eim, player, mapid) {
	switch (mapid) {
	case 253000100: //BOSS地图
		em.setProperty("state", "1");
		var map = eim.getMapInstance(253000100);
		map.startMapEffect("你们真的够实力来挑战我们么.呵呵..", 5120129);
		eim.restartEventTimer(1000 * 60 * 30); //第五大关有1小时的时间
		break;
	case 253000200: //BOSS地图
		em.setProperty("state", "2");
		var map = eim.getMapInstance(253000200);
		map.startMapEffect("看来你们还不知道什么是绝望！让我给你们看看我的绝招!", 5120129);
		break;
	case 253000300: //BOSS地图
		em.setProperty("state", "3");
		var map = eim.getMapInstance(253000300);
		// map.spawnNpc(3003207, new java.awt.Point(1167, -378));//创建防毒面具
		map.startMapEffect("你们很勇敢...也很强大....但是还是不如我这般优秀....", 5120129);
		eim.restartEventTimer(1000 * 60 * 30); //第五大关有1小时的时间
		break;
	}
	switch (mapid) {
	case 253000100: //BOSS地图1
	case 253000200: //BOSS地图2
	case 253000300: //BOSS地图2
		return
	}
	player.dropMessage(6, "[卧虎藏龙] 已退出挑战。");
	eim.unregisterPlayer(player);
	if (eim.getPlayerCount() <= 0) {
		eim.disposeIfPlayerBelow(100, 706041008);
	}
}

function playerExit(eim, player) {
	eim.disposeIfPlayerBelow(100, 706041008);
}

function playerDisconnected(eim, player) {
	eim.unregisterPlayer(player);
	return 0;
}

function openNpc(eim, npcid, mode) {
	for (var i = 0; i < eim.getPlayerCount(); i++) {
		eim.getPlayers().get(i).openNpc(npcid, mode);
	}
}

function monsterValue(eim, mobid) {
	if (mobid == 9601013) {
		eim.getMapFactory().getMap(253000100).killAllMonsters(true); //杀死所有怪物
		setupTask = em.schedule("warpmap", 1000 * 1 * 3, eim); //延迟3秒过图
		return 0;
	}
	if (mobid == 9601015) {
		eim.getMapFactory().getMap(253000300).killAllMonsters(true); //杀死所有怪物
		setupTask = em.schedule("warpmapa", 1000 * 1 * 3, eim); //延迟3秒召唤NPC
		return 0;
	}
	if (mobid == 9601018) {
		eim.getMapFactory().getMap(253000200).killAllMonsters(true); //杀死所有怪物
		setupTask = em.schedule("warpmapb", 1000 * 1 * 3, eim); //延迟3秒召唤NPC
		return 0;
	}

	return 1;
}

function warpmap(eim, player) {
	if (eim.getMapFactory().getMap(253000100).getCharactersSize() != 0) {
		openNpc(eim, 0, "WhclDeath");
	}
}

function warpmapa(eim, player) {
	if (eim.getMapFactory().getMap(253000300).getCharactersSize() != 0) {
		openNpc(eim, 0, "WhclDeath");
	}
}

function warpmapb(eim, player) {
	if (eim.getMapFactory().getMap(253000200).getCharactersSize() != 0) {
		openNpc(eim, 0, "WhclDeath");
	}
}

function playerExit(eim, player) {
	eim.unregisterPlayer(player);
	if (eim.disposeIfPlayerBelow(0, 0)) {
		em.setProperty("state", "0");
		em.setProperty("leader", "true");
	}
}
//时间到
function scheduledTimeout(eim) {
	eim.broadcastPlayerMsg(1, "[卧虎藏龙] 真遗憾！已超过限定挑战时间，本次挑战失败！别气馁，期待更加强大的您前来挑战~");
	eim.disposeIfPlayerBelow(100, 706041008);
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
}

//clear效果
function clearPQ(eim) {
	scheduledTimeout(eim);
}

function allMonstersDead(eim) {}

function leftParty(eim, player) {}
function disbandParty(eim) {}
function playerDead(eim, player) {}
function cancelSchedule() {}
